package ls.test;

import ls.dao.CourseDAO;
import ls.dao.DAOFactory;
import ls.entity.Course;

import java.util.List;
import java.util.Scanner;

public class CreateCourse {
    public int create(String teacher_id) {

        CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
        String course_name;
        String course_teacher;
        String course_property;
        String course_student;
        String course_hour;
        String number;
        String course_state = "无助教";
        String student_id = "null";
        Scanner scanner = new Scanner(System.in);
        System.out.println("现在开始录入课程！");
        System.out.print("请输入课程名：");
        course_name = scanner.next();
        System.out.print("请输入您的姓名：");
        course_teacher = scanner.next();
        System.out.print("请输入课程性质（必修课/选修课）：");
        course_property = scanner.next();
        System.out.print("请输入授课对象（本科生/研究生）：");
        course_student = scanner.next();
        System.out.print("请输入课程学时：");
        course_hour = scanner.next();
        System.out.print("请输入选课人数：");
        number = scanner.next();
        Course course = new Course();
        course.setCourse_name(course_name);
        course.setCourse_teacher(course_teacher);
        course.setCourse_property(course_property);
        course.setCourse_student(course_student);
        course.setCourse_hour(course_hour);
        course.setNumber(number);
        course.setCourse_state(course_state);
        course.setTeacher_id(teacher_id);
        course.setStudent_id(student_id);
        TeacherEvaluate te = new TeacherEvaluate();
        List<Course> courseList = courseDAO.getMyCourse(teacher_id);
        for (int i = 0;i < courseList.size();i++)
        {
            Course course1 = courseList.get(i);
            if(course_name.equals(course1.getCourse_name()) && course_property.equals(course1.getCourse_property())
            && course_student.equals(course1.getCourse_student()))
            {
                System.out.println("您的该课程已存在课程表中，请勿重复录入！");

                int m = te.middle(teacher_id);
                if(m == 0) return 0;
            }
        }
        courseDAO.addCourse(course);
        System.out.println("课程添加成功！");
        int m = te.middle(teacher_id);
        if(m == 0) return 0;
        return 0;
    }
}
